/*
 * Amkai Enterprise Solution (AES.) 
 * Copyright 2004 by Amkai(TM), Inc.
 * www.amkai.com
 * 
 * Project: webservice
 * Package: com.amkai.aes.webservice.binary.objecthandler
 * File: LogoutHandler.java
 * Created: Feb 23, 2006 12:33:47 PM
 * Author: Dudas Peter (peter) 
 * 
 */
package com.amkai.aes.webservice.binary.objecthandler;

import java.io.Serializable;

import javax.servlet.http.HttpSession;

import com.amkai.aes.aescommon.service.binary.job.LogoutJob;
import com.amkai.aes.aescommon.service.result.LogoutResult;
import com.amkai.aes.server.locking.LockManager;
import com.amkai.aes.server.session.Connection;
import com.amkai.aes.server.session.ServiceSessionManager;
import com.amkai.aes.webservice.binary.JobObjectHandler;

public class LogoutHandler implements JobObjectHandler<LogoutJob, Serializable, LogoutResult> {

	public LogoutResult process(LogoutJob job, Serializable object) throws Exception {
		LogoutResult result = new LogoutResult();
		try {
			Connection connection = ServiceSessionManager.getConnection();
			if (connection != null) {
				if (connection.getSession() != null)
					LockManager.instance.killLocks(connection.getSession().getId());
				connection.setRuntimePassport(null);
				connection.setTimeZone(null);
				connection.setConnected(false);
				if (!job.beforeLogin) {
					connection.invalidate();
				}
			}
			result.setSuccessed(true);
		}
		catch (Exception ex) {
			result.setSuccessed(false);
		}
		return result;
	}

}
